#ifndef DATAFORM_H
#define DATAFORM_H

#include <QWidget>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QResizeEvent>
#include <QVector>
#include <QTableWidgetItem>

namespace Ui {
class DataForm;
}

typedef struct ScoreItem {
    int item_id;
    int score;
} ScoreItem;

typedef struct Score {
    int row;
    int sum;
    int sort;
    struct ScoreItem *items;
} Score;

typedef struct WeekScoreItem {
    int score[5];  // 5周
} WeekScoreItem;

typedef struct WeekScore {
    int row;
    float average;
    int month_sort;
    int sort[5];
    struct WeekScoreItem *items;
} WeekScore;

typedef struct TermScoreItem {
    int score;
    int sort;
} TermScoreItem;

typedef struct TermScore {
    int row;
    struct TermScoreItem *items;
} TermScore;

class DataForm : public QWidget
{
    Q_OBJECT

public:
    explicit DataForm(QWidget *parent = nullptr);
    ~DataForm();

protected:
    void resizeEvent(QResizeEvent *event);

private slots:
    void on_add_class_clicked();

    void on_add_item_clicked();

    void on_date_combobox_activated(int index);

    void on_refresh_btn_clicked();

    void on_plus_score_btn_clicked();

    void on_minus_score_btn_clicked();

private:
    Ui::DataForm *ui;
    QSqlDatabase db;
    QSqlError err;
    int date_id;
    int select_column;
    int select_row;
    int show_class_id;
    QVector<int> class_id_list;
    QVector<int> item_id_list;
    QVector<Score> score_list;
    bool is_init;

    void refresh();
};

#endif // DATAFORM_H
